#!/bin/bash

read -p "Choose install type: 1.custom 7000 2.producter 8000 3.echo 9000 4.productor and customer 7788: " t

if false; then :;
elif [ x$t = x1 ]; then
	cp -af blackhole /bin/
	echo "[Unit]"                                   >/lib/systemd/system/blackhole-c.service
	echo "After=network.target"                    >>/lib/systemd/system/blackhole-c.service
	echo "StartLimitIntervalSec=0"                 >>/lib/systemd/system/blackhole-c.service
	echo "[Service]"                               >>/lib/systemd/system/blackhole-c.service
	echo "LimitNOFILE=65535"                       >>/lib/systemd/system/blackhole-c.service
	echo "Restart=always"                          >>/lib/systemd/system/blackhole-c.service
	echo "RestartSec=3"                            >>/lib/systemd/system/blackhole-c.service
	echo "ExecStart=/bin/blackhole --mode c -p 7000"   >>/lib/systemd/system/blackhole-c.service
	echo "[Install]"                               >>/lib/systemd/system/blackhole-c.service
	echo "WantedBy=multi-user.target"              >>/lib/systemd/system/blackhole-c.service
	systemctl daemon-reload
	systemctl enable blackhole-c
	systemctl restart blackhole-c
elif [ x$t = x2 ]; then
	cp -af blackhole /bin/
	echo "[Unit]"                                   >/lib/systemd/system/blackhole-p.service
	echo "After=network.target"                    >>/lib/systemd/system/blackhole-p.service
	echo "StartLimitIntervalSec=0"                 >>/lib/systemd/system/blackhole-p.service
	echo "[Service]"                               >>/lib/systemd/system/blackhole-p.service
	echo "LimitNOFILE=65535"                       >>/lib/systemd/system/blackhole-p.service
	echo "Restart=always"                          >>/lib/systemd/system/blackhole-p.service
	echo "RestartSec=3"                            >>/lib/systemd/system/blackhole-p.service
	echo "ExecStart=/bin/blackhole --mode p -p 8000"   >>/lib/systemd/system/blackhole-p.service
	echo "[Install]"                               >>/lib/systemd/system/blackhole-p.service
	echo "WantedBy=multi-user.target"              >>/lib/systemd/system/blackhole-p.service
	systemctl daemon-reload
	systemctl enable blackhole-p
	systemctl restart blackhole-p
elif [ x$t = x3 ]; then
	cp -af blackhole /bin/
	echo "[Unit]"                                   >/lib/systemd/system/blackhole-echo.service
	echo "After=network.target"                    >>/lib/systemd/system/blackhole-echo.service
	echo "StartLimitIntervalSec=0"                 >>/lib/systemd/system/blackhole-echo.service
	echo "[Service]"                               >>/lib/systemd/system/blackhole-echo.service
	echo "LimitNOFILE=65535"                       >>/lib/systemd/system/blackhole-echo.service
	echo "Restart=always"                          >>/lib/systemd/system/blackhole-echo.service
	echo "RestartSec=3"                            >>/lib/systemd/system/blackhole-echo.service
	echo "ExecStart=/bin/blackhole --mode echo -p 9000"   >>/lib/systemd/system/blackhole-echo.service
	echo "[Install]"                               >>/lib/systemd/system/blackhole-echo.service
	echo "WantedBy=multi-user.target"              >>/lib/systemd/system/blackhole-echo.service
	systemctl daemon-reload
	systemctl enable blackhole-echo
	systemctl restart blackhole-echo
elif [ x$t = x4 ]; then
	cp -af blackhole /bin/
	echo "[Unit]"                                   >/lib/systemd/system/blackhole-pc.service
	echo "After=network.target"                    >>/lib/systemd/system/blackhole-pc.service
	echo "StartLimitIntervalSec=0"                 >>/lib/systemd/system/blackhole-pc.service
	echo "[Service]"                               >>/lib/systemd/system/blackhole-pc.service
	echo "LimitNOFILE=65535"                       >>/lib/systemd/system/blackhole-pc.service
	echo "Restart=always"                          >>/lib/systemd/system/blackhole-pc.service
	echo "RestartSec=3"                            >>/lib/systemd/system/blackhole-pc.service
	echo "ExecStart=/bin/blackhole --mode pc -p 7788"   >>/lib/systemd/system/blackhole-pc.service
	echo "[Install]"                               >>/lib/systemd/system/blackhole-pc.service
	echo "WantedBy=multi-user.target"              >>/lib/systemd/system/blackhole-pc.service
	systemctl daemon-reload
	systemctl enable blackhole-pc
	systemctl restart blackhole-pc
else
    echo "unknown choose $t"
    exit 1
fi
exit 0


uninstall-c:
	systemctl daemon-reload
	-systemctl disable --now blackhole-c
	rm -f /lib/systemd/system/blackhole-c.service

uninstall-p:
	systemctl daemon-reload
	-systemctl disable --now blackhole-p
	rm -f /lib/systemd/system/blackhole-p.service

uninstall-pc:
	systemctl daemon-reload
	-systemctl disable --now blackhole-pc
	rm -f /lib/systemd/system/blackhole-pc.service

uninstall-echo:
	systemctl daemon-reload
	-systemctl disable --now blackhole-echo
	rm -f /lib/systemd/system/blackhole-echo.service
